package com.info.controller;

import com.info.bll.UserBLL;
import com.info.model.UserInfo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "updateUserInfoByIdServlet", value = "/admin/updateUserInfoByIdServlet")
public class updateUserInfoByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取用户更新表单数据
        Integer user_id = Integer.parseInt(request.getParameter("user_id"));
        String sex = request.getParameter("sex");
        Integer age = Integer.parseInt(request.getParameter("age"));
        String address = request.getParameter("address");
        Integer role_id = Integer.parseInt(request.getParameter("role_id"));

        //传参对象数据装载
        UserInfo userInfo = new UserInfo();
        userInfo.setUser_id(user_id);
        userInfo.setSex(sex);
        userInfo.setAge(age);
        userInfo.setAddress(address);
        userInfo.setRole_id(role_id);

        //调用用户逻辑接口方法
        UserBLL userBLL = new UserBLL();
        if(userBLL.updateUserInfoById(userInfo)){
            //更新成功
            response.sendRedirect("success.jsp");
        }else {
            //更新失败
            response.sendRedirect("error.jsp");
        }

    }
}
